package com.yiwei.zhh.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.bumptech.glide.Glide;
import com.yiwei.zhh.R;
import com.yiwei.zhh.adapter.base.ItemAdapter;
import com.yiwei.zhh.model.SpreadTypeModel;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class UploadTypeAdapter extends ItemAdapter<SpreadTypeModel.DataBean.ListsBean, UploadTypeAdapter.DefaultHolder> {


    private Context context;
    private String can_post;

    public UploadTypeAdapter(Context context) {
        super(context);
        this.context = context;
    }

    public void setCan_post(String can_post) {
        this.can_post = can_post;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_upload_type, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        SpreadTypeModel.DataBean.ListsBean item = getItem(position);
        holder.txtName.setText(item.name);
        holder.txtContent.setText(item.desc);


        if (can_post.equals("0")) {
            holder.btnSubmit.setShapeSolidColor(0xffE4E4EE).setUseShape();
        } else {
            holder.btnSubmit.setShapeSolidColor(0xff4C81FF).setUseShape();
        }
        holder.btnSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onChooseListener != null) {
                    onChooseListener.onClick(can_post, item.id, item.name);
                }
            }
        });
        switch (item.id) {
            case "4":
                Glide.with(context).load(R.mipmap.img_upload_type_tiezi).into(holder.imgIcon);
                break;
            case "3":
                Glide.with(context).load(R.mipmap.img_upload_type_duanshipin).into(holder.imgIcon);
                break;
            case "1":
                Glide.with(context).load(R.mipmap.img_upload_type_pengyouquan).into(holder.imgIcon);
                break;
            case "2":
                Glide.with(context).load(R.mipmap.img_upload_type_haoyoulian).into(holder.imgIcon);
                break;
            case "9":
                Glide.with(context).load(R.mipmap.img_upload_type_other).into(holder.imgIcon);
                break;
        }

    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_icon)
        ImageView imgIcon;
        @BindView(R.id.txt_name)
        TextView txtName;
        @BindView(R.id.txt_content)
        TextView txtContent;
        @BindView(R.id.btn_submit)
        SuperButton btnSubmit;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onClick(String can_post, String id, String type);
    }

}
